package com.hdsx.springboot.config;

import com.hdsx.springboot.bean.Person;
import com.hdsx.springboot.bean.User;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author 占贤银
 * time 2024/5/27 22:17
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public class MyImportSelector implements ImportBeanDefinitionRegistrar, ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        return new String[]{User.class.getName()};
    }

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                        BeanDefinitionRegistry registry) {
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(Person.class);
        beanDefinition.setBeanClassName(Person.class.getName());
        registry.registerBeanDefinition("person", beanDefinition);
    }
}
